﻿
Pages_Report_ReportPaymentOut = new function () {
    this.ObjSearch = {
        AccountId: -1,
        TypeId: -1,
        AccountName: '',
        FromDate: '1/1/2012',
        ToDate:'1/1/2030'
    };
    

    this.m_objPagePaymentOut = new VtcPaging("divPaymentOutPaging", "Pages_Report_ReportPaymentOut.bindData", "pagingCss", 10, CONSTANT.PAGE_DISPLAY);
    this.getOptionSearch = function() {
        this.ObjSearch.AccountId = parseInt($("#txtAccountId").val());
        this.ObjSearch.AccountId = this.ObjSearch.AccountId > 0 ? this.ObjSearch.AccountId : -1;        
        
        this.ObjSearch.TypeId = $("#ddlTypeId").val();

        this.ObjSearch.AccountName = $("#txtAccountName").val();
        this.ObjSearch.FromDate = $("#txtFromDate").val();
        this.ObjSearch.ToDate = $("#txtToDate").val();
    };
    this.documentReady = function () {
        this.getOptionSearch();
        this.bindData(1, this.m_objPagePaymentOut.pageSize);
    };

    this.bindData = function (_cur, _ps) {
        Loading.showProcess();        
        $.ajax({
            type: "GET",
            url: "/handler/HandlerReport.ashx",
            data: {
                accountId: this.ObjSearch.AccountId, typeId: this.ObjSearch.TypeId, accountName: this.ObjSearch.AccountName,
                fromDate: this.ObjSearch.FromDate, toDate:this.ObjSearch.ToDate, currentPage: _cur, pageSize: _ps, t: "rptPaymentOut"
            },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Pages_Report_ReportPaymentOut.processData(data, _cur);
                Loading.closeProcess();
            }
        });

    };

    this.processData = function (data, _cur) {
        
        $("#thTotalByGateway").setTemplate('{#foreach $T.Gates as gate}'
            + '<tr class="category">'
            + '     <td align="left"><span class="norB">Đã đổi qua {$T.gate.Name}</span></td><td>{$T.gate.TotalReceiveVnd>0?COMMON.formatMoney($T.gate.TotalReceiveVnd):0} VNĐ</td><td>{$T.gate.TotalReceiveAmount>0?COMMON.formatMoney($T.gate.TotalReceiveAmount):0} {$T.gate.Unit}</td>'
            + '</tr>'
            + '{#/for}');
        $("#thTotalByGateway").processTemplate(data);
        
        $("#spTotalAdmin").html('(' + data.TotalRecord.toString() + ')');
        $("#tdTotalAuOut").html(COMMON.formatMoney(data.TotalAuOut));
        $("#tdTotalVndOut").html(COMMON.formatMoney(data.TotalVndOut)+" VNĐ");
        
        $("#divPaymentOut").setTemplateURL("/Template/Pages/Report/rptPaymentOut.htm");
        $("#divPaymentOut").processTemplate(data);
        Pages_Report_ReportPaymentOut.setStyleRow("#divPaymentOut");
        Pages_Report_ReportPaymentOut.m_objPagePaymentOut.bindPaging(_cur, data.TotalRecord);
        if (data.TotalRecord <= Pages_Report_ReportPaymentOut.m_objPagePaymentOut.pageSize) {
            $("#divPaymentOutPaging").attr('style', 'display:none');
        }
        else {
            $("#divPaymentOutPaging").attr('style', 'display:block');
        }
    };
   
    $("#btnSearch").live('click', function () {
        Pages_Report_ReportPaymentOut.documentReady();
        
    });

   
    this.setStyleRow = function (m_selParent) {
        var m_stt = 0;
        $('#divItem', m_selParent).each(function () {
            m_stt++;
            if ((m_stt % 2) == 0) {
                $(this.parentNode).addClass('even');
            }
            else {
                $(this.parentNode).addClass('odd');
            }
        });
    };       
}